package baseFx.database.mybatis;

import baseFx.database.MultipleReader;
import baseFx.database.SqlParam;

import java.util.List;
import java.util.Map;

public class MybatisMultipleReader implements MultipleReader {
    private List<List<Map<?,?>>> results;
    private SqlParam param;

    MybatisMultipleReader(List<List<Map<?,?>>> results, SqlParam param) {
        this.results = results;
        this.param = param;
    }

    @Override
    public <T> List<T> read(Class<T> clazz) {
        List<Map<?,?>> rows = results.remove(0);
        return param.convert(clazz, rows);
    }

    @Override
    public void close() {
        if (results != null) {
            results.clear();
            results = null;
        }
        param = null;
    }
}
